﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using MySql.Data.MySqlClient;

namespace DAL
{
    /// <summary>
    ///BBSDAL 的摘要说明
    /// </summary>
    public class BBSDAL
    {
        public DataTable GeteData(string id,long time)
        {
            MySqlDataAdapter adapter = null;
            string sql = "select tid,subject,author,dateline from  pre_forum_post where dateline>"+time.ToString()+" and fid=" + id + " and bbcodeoff=0 and first=1 and status not in (1,2,3) order by dateline desc limit 0 ,20";
            adapter = new MySqlDataAdapter(sql, DBManager.BBS);
            DataTable tb = new DataTable();
            adapter.Fill(tb);
            return tb;
        }

        public DataTable GeteData(string id, int count)
        {
            MySqlDataAdapter adapter = null;
            string sql = "select * from  pre_forum_post where fid=" + id + " and invisible=0 and first=1  order by dateline desc limit 0 ," + count;
            adapter = new MySqlDataAdapter(sql, DBManager.BBS);
            DataTable tb = new DataTable();
            adapter.Fill(tb);
            return tb;
        }

        public DataTable GeteDataByTypeid(int typeid, int count)
        {
            MySqlDataAdapter adapter = null;
            string sql = "select a.*,b.typeid from  pre_forum_post as a left join pre_forum_thread as b on a.tid=b.tid where b.typeid=" + typeid + " and a.invisible=0 and a.first=1 and a.tags>'0' order by a.dateline desc limit 0 ," + count;
            adapter = new MySqlDataAdapter(sql, DBManager.BBS);
            DataTable tb = new DataTable();
            adapter.Fill(tb);
            return tb;
        }

        public DataTable GetAttachment(long aid)
        {
            string sql = "select * from pre_forum_attachment where aid=" + aid;
            MySqlDataAdapter adapter = null;
            adapter = new MySqlDataAdapter(sql, DBManager.BBS);
            DataTable tb = new DataTable();
            adapter.Fill(tb);
            return tb;
        }
    }
}